<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class ModifyColumnTypeInDelayOrderTaskTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function up()
    {
        $this->table('delay_order_task')
            ->changeColumn('type', 'enum', ['values' => 'request_delay,today_done,demand_order,downstream_delay,work_order', 'default' => 'request_delay', 'comment' => '延期任务类型(申请延期 request_delay, 今日完成 today_done,需求单 demand_order,工单 work_order)'])
            ->addColumn('link_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '关联ID（工单ID｜需求单ID）'])
            ->addIndex(['link_id', 'type'], ['type' => 'normal', 'name' => 'link_type'])
            ->save();
    }

    public function down()
    {
        $this->table('delay_order_task')
            ->changeColumn('type', 'enum', ['values' => 'request_delay,today_done,demand_order,downstream_delay', 'default' => 'request_delay', 'comment' => '延期任务类型(申请延期 request_delay, 今日完成 today_done,需求单 demand_order)'])
            ->removeColumn('link_id')
            ->removeIndexByName('link_type')
            ->save();
    }

}
